package com.qf.mvc01.controller;
import com.qf.mvc01.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/uc")
public class UserController {

    /**
     * 查询用户,返回user.html
     * @return
     */
    @RequestMapping("/query")
    public String queryUser(){
        System.out.println("show user information");
        return "/views/user.html";
    }

    /** http://localhost:8080/uc/query?id=1&name=zzz&gender=false&birth=2018-12-12 12:20:30&hobby=basketball&hobbby=football&hobby=swimming
     * 添加用户,并且重定向到queryUser
     * @param user
     * @return
     */
    @RequestMapping("/add")
    public String addUser(User user){
        System.out.println(user);
        return "redirect:/uc/query";
    }


    /**
     * 通过路径收参，删除用户，并且重定向到queryUser
     * @param id
     * @return
     */
    @RequestMapping("/del/{id}")
    public String delUser(@PathVariable("id") Integer id){
        System.out.println("用户id为"+id+"的用户已经被删除");
        return "redirect:/uc/query";
    }
}
